﻿@page "/export"

@inject IUserBasketService basketService
@inject ViewDataService ViewDataService
@inject IJSRuntime JsRuntime
@inject NavigationManager navManager

<div class="damselfly-exportview">
    <div class="damselfly-pagetitlebar">
        <NavBack/>
        <h4 class="damselfly-imagetitle">
            Export Images
        </h4>
    </div>
    <div class="damselfly-exportlist">
        @if( images != null )
        {
            @foreach( var img in images )
            {
                <div class="damselfly-exportitem">
                    <div>
                        <img title="@img.Image.FileName" src="@img.ThumbURL">
                    </div>
                    <div>
                        @img.Image.FileName
                    </div>
                    <div>
                        @img.Image.Folder.Name
                    </div>
                </div>
            }
        }
        else
        {
            <p>Loading selection...</p>
        }
    </div>
</div>

@code {
    readonly List<ListableImage> images = new();


    public Task<List<ListableImage>> LoadData()
    {
        var watch = new Stopwatch("ExportLoadData");
        images.Clear();
        images.AddRange(basketService.BasketImages.Select(x => new ListableImage(x, ThumbSize.Medium)));
        watch.Stop();

        return Task.FromResult(images);
    }


    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if( firstRender )
        {
            ViewDataService.SetSideBarState(new ViewDataService.SideBarState { ShowExport = true });

            await LoadData();

            StateHasChanged();
        }
    }

}